import 'package:amoy_ticket/movie/movie_tabbar_one.dart';
import 'package:amoy_ticket/movie/movie_tabbar_three.dart';
import 'package:amoy_ticket/movie/movie_tabbar_two/movie_tabbar_two.dart';
import 'package:amoy_ticket/utils/sticky_tabBar_delegate.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'movie_tabbar_four.dart';

class MovieMainPage extends StatefulWidget {
  MovieMainPage({Key? key}) : super(key: key);

  @override
  _MovieMainPageState createState() => _MovieMainPageState();
}

class _MovieMainPageState extends State<MovieMainPage>
    with SingleTickerProviderStateMixin {
  late TabController _tabController;
  List _tabs = [
    '热映',
    '影院',
    '即将上映',
    '在线看',
  ];

  @override
  void initState() {
    super.initState();

    _tabController = TabController(length: _tabs.length, vsync: this);
    _tabController.addListener(() {
      if (_tabController.index == 0) {
      } else {}
      setState(() {});
    });
  }

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Scaffold(
          body: NestedScrollView(
        headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
          return [
            SliverAppBar(
              automaticallyImplyLeading: false,
              elevation: 10,
              pinned: false,
              backgroundColor: Colors.white,
              flexibleSpace: Padding(
                padding: EdgeInsets.symmetric(vertical: 8.h, horizontal: 10.w),
                child: Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    GestureDetector(
                      child: Row(
                        children: [
                          Text(
                            '南京',
                            style: TextStyle(
                                fontSize: 12.sp, fontWeight: FontWeight.bold),
                          ),
                          Icon(
                            Icons.arrow_drop_down,
                            size: 20.r,
                          )
                        ],
                      ),
                    ),
                    Expanded(
                      child: Container(
                        margin: EdgeInsets.symmetric(horizontal: 10.w),
                        padding: EdgeInsets.symmetric(
                            horizontal: 5.w, vertical: 5.h),
                        // height: 30.h,
                        decoration: BoxDecoration(
                          color: Color(0xFFf5f6f8),
                          borderRadius: BorderRadius.all(
                            Radius.circular(20.r),
                          ),
                        ),
                        child: Row(
                          children: [
                            Icon(
                              Icons.search,
                              size: 16.r,
                              color: Color(0xFFa0a2c9),
                            ),
                            Expanded(
                              child: Text(
                                '搜影片、影院、影人、演出、资讯、视频',
                                overflow: TextOverflow.ellipsis,
                                maxLines: 1,
                                style: TextStyle(
                                    color: Color(0xFFa0a2c9), fontSize: 12.sp),
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                    GestureDetector(
                      child: Image.asset(
                        'assets/images/scan_icon.png',
                        width: 23.w,
                        height: 23.w,
                        // color: Colors.,
                      ),
                    ),
                  ],
                ),
              ),
            ),
            SliverPersistentHeader(
              pinned: true,
              delegate: StickyTabBarDelegate(
                child: TabBar(
                  dragStartBehavior: DragStartBehavior.start,
                  key: GlobalKey(),
                  controller: _tabController,
                  labelColor: Color(0xFF30333d),

                  // indicator: RoundUnderlineTabIndicator(
                  //     borderSide: BorderSide(width: 3.0, color: Colors.red),
                  //     width: 20.w),
                  unselectedLabelColor: Color(0xFFa1a4ad),
                  indicatorSize: TabBarIndicatorSize.label,
                  labelStyle:
                      TextStyle(fontWeight: FontWeight.bold, fontSize: 13.sp),
                  unselectedLabelStyle: TextStyle(fontSize: 12.sp),
                  tabs: _tabs.map((e) {
                    return Tab(
                      text: e,
                    );
                  }).toList(),
                ),
              ),
            )
          ];
        },
        body: TabBarView(
          controller: _tabController,
          children: [
            MovieTabBarOne(),
            MovieTabBarTwo(),
            MovieTabBarThree(),
            MovieTabBarFour(),
          ],
        ),
      )),
    );
  }
}
